<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>STRATEGIC CONSTRUCTION:  Fichier source de /Users/pierre-loupbarazzutti/Desktop/svn/silverstarlif7/projet/src/Cases.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">STRATEGIC CONSTRUCTION
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Généré par Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Page&#160;principale</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Fichiers</span></a></li>
      <li><a href="dirs.html"><span>Répertoires</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Liste&#160;des&#160;fichiers</span></a></li>
      <li><a href="globals.html"><span>Membres&#160;de&#160;fichier</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_cases_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Cases.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_cases_8c.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="_cases_8h.html">Cases.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="_unite_8h.html">Unite.h</a>&quot;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00006"></a>00006 
<a name="l00007"></a><a class="code" href="_cases_8h.html#aa22815cc4f237714fa0ef5a1749daf36">00007</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(<a class="code" href="structs_cases.html">Cases</a> *c)
<a name="l00008"></a>00008 {
<a name="l00009"></a>00009         (*c).lunite = NULL;
<a name="l00010"></a>00010         (*c).type_decor = 0;    
<a name="l00011"></a>00011         (*c).groupe_decor = 0; 
<a name="l00012"></a>00012         (*c).vie = 100;
<a name="l00013"></a>00013 }
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="_cases_8h.html#aa30b79324f9aa68e3249d4b455829540">00015</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#aa30b79324f9aa68e3249d4b455829540">DestructionCases</a>(<a class="code" href="structs_cases.html">Cases</a> *c)
<a name="l00016"></a>00016 {
<a name="l00017"></a>00017         <span class="keywordflow">if</span> ((*c).lunite != NULL)
<a name="l00018"></a>00018         {
<a name="l00019"></a>00019                 <a class="code" href="_unite_8c.html#a2df5f84d40b0cfdc35a2e9e780f59429">DestructionUnite</a>((*c).lunite);
<a name="l00020"></a>00020                 free((*c).lunite);
<a name="l00021"></a>00021         }
<a name="l00022"></a>00022         (*c).type_decor = 0;
<a name="l00023"></a>00023         (*c).groupe_decor = 0;
<a name="l00024"></a>00024         (*c).vie = 0;
<a name="l00025"></a>00025         (*c).lunite = NULL;
<a name="l00026"></a>00026 }
<a name="l00027"></a>00027 
<a name="l00028"></a><a class="code" href="_cases_8h.html#a6653080275f128c807592b02d9178be5">00028</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#a6653080275f128c807592b02d9178be5">DeplacementUniteCases</a> (<a class="code" href="structs_cases.html">Cases</a> * cdepart, <a class="code" href="structs_cases.html">Cases</a> * cfin)
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030         assert( (*cdepart).lunite != NULL);
<a name="l00031"></a>00031         assert( (*cfin).lunite == NULL);
<a name="l00032"></a>00032         (*cfin).lunite = (*cdepart).lunite;
<a name="l00033"></a>00033         (*cdepart).lunite = NULL;
<a name="l00034"></a>00034 }
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="_cases_8h.html#afa7f5bc3d7529b50515d2f065b1b3daa">00036</a> <span class="keywordtype">int</span> <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(<a class="code" href="structs_cases.html">Cases</a> * u,<a class="code" href="structs_cases.html">Cases</a> * element,<span class="keywordtype">int</span> action)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038         <span class="keywordtype">int</span> resultat;
<a name="l00039"></a>00039         assert( (*u).lunite != NULL);
<a name="l00040"></a>00040         <span class="keywordflow">if</span> (action == 1) <span class="comment">/* Couper du bois */</span>
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042                 (*element).vie = (*element).vie - 50;
<a name="l00043"></a>00043                 <span class="keywordflow">if</span> ((*element).vie &lt;= 0)
<a name="l00044"></a>00044                 {
<a name="l00045"></a>00045                         <a class="code" href="_cases_8c.html#a6eee1057f6463a6cb9afbc6c83ee4419">ModificationDecor</a> (element, 0,0);
<a name="l00046"></a>00046                 }
<a name="l00047"></a>00047         }
<a name="l00048"></a>00048         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (action == 2) <span class="comment">/* Faire un combat */</span>
<a name="l00049"></a>00049         {
<a name="l00050"></a>00050                 assert( (*element).lunite != NULL);
<a name="l00051"></a>00051                 resultat = <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a>((*u).lunite,(*element).lunite);
<a name="l00052"></a>00052                 <span class="keywordflow">if</span> (resultat == 1)
<a name="l00053"></a>00053                 {
<a name="l00054"></a>00054                         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(element);
<a name="l00055"></a>00055                         <span class="keywordflow">return</span> 2;
<a name="l00056"></a>00056                 }
<a name="l00057"></a>00057                 <span class="keywordflow">if</span> (resultat == 2)
<a name="l00058"></a>00058                 {
<a name="l00059"></a>00059                         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(u);
<a name="l00060"></a>00060                         <span class="keywordflow">return</span> 1;
<a name="l00061"></a>00061                 }
<a name="l00062"></a>00062         }
<a name="l00063"></a>00063         <span class="keywordflow">return</span> 0;
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065 
<a name="l00066"></a><a class="code" href="_cases_8h.html#a6eee1057f6463a6cb9afbc6c83ee4419">00066</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#a6eee1057f6463a6cb9afbc6c83ee4419">ModificationDecor</a> (<a class="code" href="structs_cases.html">Cases</a> * c, <span class="keywordtype">int</span> type, <span class="keywordtype">int</span> equipe)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068         (*c).type_decor = type;
<a name="l00069"></a>00069         (*c).vie = 100;
<a name="l00070"></a>00070         (*c).groupe_decor = equipe;
<a name="l00071"></a>00071 }
<a name="l00072"></a>00072 
<a name="l00073"></a><a class="code" href="_cases_8h.html#a82382858b44a9b5dea9136eadac8cee1">00073</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a> (<a class="code" href="structs_cases.html">Cases</a> * c)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075         <a class="code" href="_unite_8c.html#a2df5f84d40b0cfdc35a2e9e780f59429">DestructionUnite</a>((*c).lunite);
<a name="l00076"></a>00076         free ((*c).lunite);
<a name="l00077"></a>00077         (*c).lunite = NULL;
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 
<a name="l00080"></a><a class="code" href="_cases_8h.html#add2687021c6d17fd31d5342b369d89ba">00080</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (<a class="code" href="structs_cases.html">Cases</a> * c, <span class="keywordtype">int</span> type, <span class="keywordtype">int</span> equipe)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082         (*c).lunite = (<a class="code" href="structs_unite.html">Unite</a>*) malloc (<span class="keyword">sizeof</span> (<a class="code" href="structs_unite.html">Unite</a>));
<a name="l00083"></a>00083         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>((*c).lunite,type,equipe);
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00086"></a><a class="code" href="_cases_8h.html#a88e4c5d59e79fef6cd26a1b75cf3e78c">00086</a> <span class="keywordtype">void</span> <a class="code" href="_cases_8c.html#a88e4c5d59e79fef6cd26a1b75cf3e78c">CasesTestRegression</a>()
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088         <a class="code" href="structs_cases.html">Cases</a> * ctest = (<a class="code" href="structs_cases.html">Cases</a>*) malloc(<span class="keyword">sizeof</span> (<a class="code" href="structs_cases.html">Cases</a>));
<a name="l00089"></a>00089         <a class="code" href="structs_cases.html">Cases</a> * ctest2 = (<a class="code" href="structs_cases.html">Cases</a>*) malloc(<span class="keyword">sizeof</span> (<a class="code" href="structs_cases.html">Cases</a>));
<a name="l00090"></a>00090         <span class="keywordtype">int</span> retour;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092         <span class="comment">/* Vérification de la procédure InitialisationCases */</span>
<a name="l00093"></a>00093         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00094"></a>00094         assert( (*ctest).lunite == NULL);
<a name="l00095"></a>00095         assert( (*ctest).type_decor == 0);
<a name="l00096"></a>00096         assert( (*ctest).groupe_decor == 0);
<a name="l00097"></a>00097         assert( (*ctest).vie == 100);
<a name="l00098"></a>00098         printf(<span class="stringliteral">&quot;Procédure InitialisationCases ok \n&quot;</span>);
<a name="l00099"></a>00099 
<a name="l00100"></a>00100         <span class="comment">/* Vérification de la procédure DestructionCases */</span>
<a name="l00101"></a>00101         <a class="code" href="_cases_8c.html#aa30b79324f9aa68e3249d4b455829540">DestructionCases</a>(ctest);
<a name="l00102"></a>00102         assert( (*ctest).type_decor == 0);
<a name="l00103"></a>00103         assert( (*ctest).groupe_decor == 0);
<a name="l00104"></a>00104         assert( (*ctest).vie == 0);
<a name="l00105"></a>00105         assert( (*ctest).lunite == NULL);
<a name="l00106"></a>00106         printf(<span class="stringliteral">&quot;Procédure DestructionCases ok \n&quot;</span>);
<a name="l00107"></a>00107 
<a name="l00108"></a>00108         <span class="comment">/* Vérification de la procédure ModificationDecor */</span>
<a name="l00109"></a>00109         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00110"></a>00110         <a class="code" href="_cases_8c.html#a6eee1057f6463a6cb9afbc6c83ee4419">ModificationDecor</a> (ctest, 1, 1);
<a name="l00111"></a>00111         assert( (*ctest).type_decor == 1);
<a name="l00112"></a>00112         assert( (*ctest).groupe_decor == 1);
<a name="l00113"></a>00113         assert( (*ctest).vie == 100);
<a name="l00114"></a>00114         printf(<span class="stringliteral">&quot;Procédure ModificationDecor ok \n&quot;</span>);
<a name="l00115"></a>00115         
<a name="l00116"></a>00116         <span class="comment">/* Vérification de la procédure CreationUniteCases */</span>
<a name="l00117"></a>00117         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00118"></a>00118         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest, 1, 1);
<a name="l00119"></a>00119         assert( (*ctest).lunite != NULL);
<a name="l00120"></a>00120         printf(<span class="stringliteral">&quot;Procédure CreationUniteCases ok \n&quot;</span>);
<a name="l00121"></a>00121         
<a name="l00122"></a>00122         <span class="comment">/* Vérification de la procédure DestructionUniteCases */</span>
<a name="l00123"></a>00123         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(ctest);
<a name="l00124"></a>00124         assert( (*ctest).lunite == NULL);
<a name="l00125"></a>00125         printf(<span class="stringliteral">&quot;Procédure DestructionUniteCases ok \n&quot;</span>);
<a name="l00126"></a>00126         
<a name="l00127"></a>00127         <span class="comment">/* Vérification de la procédure DeplacementUniteCases */</span>
<a name="l00128"></a>00128         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest2);
<a name="l00129"></a>00129         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest, 1, 1);
<a name="l00130"></a>00130         <a class="code" href="_cases_8c.html#a6653080275f128c807592b02d9178be5">DeplacementUniteCases</a>(ctest, ctest2);
<a name="l00131"></a>00131         assert( (*ctest).lunite == NULL);
<a name="l00132"></a>00132         assert( (*ctest2).lunite != NULL);
<a name="l00133"></a>00133         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(ctest2);
<a name="l00134"></a>00134         printf(<span class="stringliteral">&quot;Procédure DeplacementUniteCases ok \n&quot;</span>);
<a name="l00135"></a>00135         
<a name="l00136"></a>00136         <span class="comment">/* Vérification de la procédure ActionUniteCases */</span>
<a name="l00137"></a>00137         <span class="comment">/* test passant dans la boucle if (action == 1) */</span>
<a name="l00138"></a>00138         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00139"></a>00139         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest2);
<a name="l00140"></a>00140         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest, 1, 0);
<a name="l00141"></a>00141         <a class="code" href="_cases_8c.html#a6eee1057f6463a6cb9afbc6c83ee4419">ModificationDecor</a> (ctest2, 1, 0);
<a name="l00142"></a>00142         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,1);
<a name="l00143"></a>00143         assert( (*ctest2).vie == 50);
<a name="l00144"></a>00144         assert( retour == 0);
<a name="l00145"></a>00145         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,1);
<a name="l00146"></a>00146         assert( retour == 0);
<a name="l00147"></a>00147         assert( (*ctest2).vie == 100);
<a name="l00148"></a>00148         assert( (*ctest2).type_decor == 0);
<a name="l00149"></a>00149         assert( (*ctest2).groupe_decor == 0);
<a name="l00150"></a>00150         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(ctest);
<a name="l00151"></a>00151         
<a name="l00152"></a>00152         <span class="comment">/* test passant dans la boucle if (action == 2) </span>
<a name="l00153"></a>00153 <span class="comment">                L&#39;unité de la case ctest gagne le combat */</span>
<a name="l00154"></a>00154         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00155"></a>00155         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest2);
<a name="l00156"></a>00156         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest, 5, 0);
<a name="l00157"></a>00157         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest2, 3, 1);
<a name="l00158"></a>00158         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,2);
<a name="l00159"></a>00159         assert( retour == 0);
<a name="l00160"></a>00160         assert( (*(*ctest2).lunite).vie &lt; 100);
<a name="l00161"></a>00161         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,2);
<a name="l00162"></a>00162         assert( retour == 2);
<a name="l00163"></a>00163         assert( (*ctest2).lunite == NULL);
<a name="l00164"></a>00164         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(ctest);
<a name="l00165"></a>00165         
<a name="l00166"></a>00166         <span class="comment">/* L&#39;unité de la case ctest2 gagne le combat */</span>        
<a name="l00167"></a>00167         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest);
<a name="l00168"></a>00168         <a class="code" href="_cases_8c.html#aa22815cc4f237714fa0ef5a1749daf36">InitialisationCases</a>(ctest2);
<a name="l00169"></a>00169         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest, 3, 0);
<a name="l00170"></a>00170         <a class="code" href="_cases_8c.html#add2687021c6d17fd31d5342b369d89ba">CreationUniteCases</a> (ctest2, 5, 1);
<a name="l00171"></a>00171         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,2);
<a name="l00172"></a>00172         assert( retour == 0);
<a name="l00173"></a>00173         assert( (*(*ctest).lunite).vie &lt; 100);
<a name="l00174"></a>00174         retour = <a class="code" href="_cases_8c.html#afa7f5bc3d7529b50515d2f065b1b3daa">ActionUniteCases</a>(ctest,ctest2,2);
<a name="l00175"></a>00175         assert( retour == 1);
<a name="l00176"></a>00176         assert( (*ctest).lunite == NULL);
<a name="l00177"></a>00177         printf(<span class="stringliteral">&quot;Procédure ActionUniteCases ok \n&quot;</span>);
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <a class="code" href="_cases_8c.html#a82382858b44a9b5dea9136eadac8cee1">DestructionUniteCases</a>(ctest2);
<a name="l00180"></a>00180         
<a name="l00181"></a>00181         free(ctest);
<a name="l00182"></a>00182         free(ctest2);
<a name="l00183"></a>00183         
<a name="l00184"></a>00184 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_cases_8c.html">Cases.c</a>      </li>

    <li class="footer">Généré le Jeudi Juin 7 2012 11:43:12 pour STRATEGIC CONSTRUCTION par
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
